package fall2014.cs343.lab2.multithreading;

/**
 * 
 * B - Simple Thread class.
 * 
 * This class introduces basic concepts in setting up an application
 * with multiple threads.
 *
 */
public class B extends Thread{

	private static int asset = 0;
	private static int data = 0;
	public static final int iterations = 200;

	/**
	 * Default Constructor
	 */
	public B() {
		data = 0;
	}

	/**
	 * Constructor with String param
	 * 
	 * @param name
	 */
	public B(String name) {
		super(name);
	}

	/**
	 * rest - pauses for "time" milliseconds
	 * @param time
	 */
	private void rest(int time){
		try {
			sleep(time);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}		
	}
	
	/**
	 * public void run method
	 * 
	 *  - this is where the work gets done in the thread
	 */
	public void run(){
		for (int i=0; i < iterations; i++){
			data ++;
			if (data<=100){
				rest(1);
				asset = data * 10;
			}
			System.out.println(" " + getName() + ": Asset is now " + asset);
		}
	}


}
